home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / rcs / fbutton.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  22.5 KB  |  879 lines

  1. head    1.4;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.4; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.4
  10. date    98.04.08.15.11.45;    author dlorre;    state Exp;
  11. branches;
  12. next    1.3;
  13.  
  14. 1.3
  15. date    97.07.14.04.21.01;    author dlorre;    state Exp;
  16. branches;
  17. next    1.2;
  18.  
  19. 1.2
  20. date    96.08.28.20.01.03;    author dlorre;    state Exp;
  21. branches;
  22. next    1.1;
  23.  
  24. 1.1
  25. date    96.08.22.02.05.10;    author dlorre;    state Exp;
  26. branches;
  27. next    ;
  28.  
  29.  
  30. desc
  31. @Oui.lib -- Object User Interface
  32. Projet créé en 1994
  33. Auteur: Dominique Lorre
  34. @
  35.  
  36.  
  37. 1.4
  38. log
  39. @label initialization moved to separate functions
  40. @
  41. text
  42. @//$Id: fbutton.cc 1.3 1997/07/14 04:21:01 dlorre Exp dlorre $
  43. #include <intuition/intuition.h>
  44. #include <intuition/classes.h>
  45. #include <intuition/classusr.h>
  46. #include <intuition/imageclass.h>
  47. #include <intuition/gadgetclass.h>
  48. #include <intuition/icclass.h>
  49. #include <intuition/cghooks.h>
  50. #include <libraries/gadtools.h>
  51.  
  52. #include <string.h>
  53. #include <stdio.h>
  54. #include <mydebug.h>
  55.  
  56. #include "screen.h"
  57. #include "window.h"
  58. #include "gadgets/fbutton.h"
  59. #include "gadgets/eclass.h"
  60. #include "gadgetlist.h"
  61.  
  62. #include <proto/exec.h>
  63. #include <proto/dos.h>
  64. #include <proto/graphics.h>
  65. #include <proto/intuition.h>
  66. #include <proto/utility.h>
  67. #include <clib/alib_protos.h>
  68. #include <compiler.h>
  69.  
  70. static int InitBoxImage(void) ;
  71. static void FreeBoxImage(void) ;
  72. static struct Image *BoxImage ;
  73.  
  74.  
  75. // Ces déclarations ne sont plus statiques puisque la classe devient globale
  76.  
  77. Class *BOOPSIfbutton ;
  78. int InitFButton(void) ;
  79. void FreeFButton(void) ;
  80.  
  81. extern "C" STDARGS ULONG HookEntry() ;
  82.  
  83.  
  84. // ========================================================================
  85. // ========================== FBUTTON CLASS ===============================
  86. // ========================================================================
  87.  
  88. fbutton::fbutton(gadgetlist *gl,
  89.                void (window::*func)(gadget *, unsigned long, unsigned short),
  90.                const char *t, BOOL def, BOOL disable) : gadget(gl, func),
  91.                                         it1(NULL), it2(NULL), it3(NULL),
  92.                                         norm1(NULL), norm2(NULL), under(NULL),
  93.                                         font(NULL), underline(NULL)
  94. {
  95.     InitBoxImage() ;
  96.     InitFButton() ;
  97.  
  98.     if (t) {
  99.         if (def) glist->setdefault(TRUE) ;
  100.         initlab(t) ;
  101.     }
  102.  
  103.     gad = gl->gad = (Gadget *)NewObject(BOOPSIfbutton, NULL,
  104.             GA_ID,          id,
  105.             GA_Top,         gl->ng->ng_TopEdge,
  106.             GA_Left,        gl->ng->ng_LeftEdge,
  107.             GA_Width,       gl->ng->ng_Width,
  108.             GA_Height,      gl->ng->ng_Height,
  109.  
  110.             GA_Immediate,   TRUE,
  111.             GA_RelVerify,   TRUE,
  112.  
  113.             GA_Previous,    gl->gad,
  114.             GA_IntuiText,   it1 ,
  115.             GA_Image,       BoxImage,
  116.  
  117.             GA_UserData,    EGA_Pulse,
  118.             GA_Disabled,    disable,
  119.             EGA_XPens,      gl->win->ws->xpens,
  120.  
  121.             TAG_END) ;
  122.  
  123.     if (def) gl->setdefault(FALSE) ;
  124. }
  125.  
  126. fbutton::~fbutton()
  127. {
  128.     freelab() ;
  129.     if (gad) DisposeObject(gad) ;
  130.     FreeFButton() ;
  131.     FreeBoxImage() ;
  132. }
  133.  
  134. void fbutton::select(BOOL sel, BOOL disable)
  135. {
  136.     SetGadgetAttrs((Gadget *)gad, w, NULL,
  137.         GA_Selected,    sel,
  138.         GA_Disabled,    disable,
  139.         TAG_END) ;
  140.     RefreshGList((Gadget *)gad, w, NULL, 1);
  141. }
  142.  
  143.  
  144. void fbutton::keystroke(BOOL shifted)
  145. {
  146.     select(TRUE) ;
  147.     Delay(5) ;
  148.     select(FALSE) ;
  149.     Delay(5) ;
  150.     gadget::action(NULL, NULL) ;
  151. }
  152.  
  153. void fbutton::action(unsigned long classe, unsigned short code)
  154. {
  155.     if (classe != IDCMP_GADGETDOWN) {
  156.         gadget::action(classe, code) ;
  157.     }
  158. }
  159.  
  160.  
  161. void fbutton::initlab(const char *t)
  162. {
  163. BOOL    underset = FALSE ;
  164. int     i, l1, l2 ;
  165.  
  166.     if (t) {
  167.  
  168.         it1 = new IntuiText ;
  169.         it2 = new IntuiText ;
  170.         it3 = new IntuiText ;
  171.  
  172.         underline = new TTextAttr ;
  173.  
  174.         it1->FrontPen = it2->FrontPen = it3->FrontPen = glist->gpen ;
  175.         it1->BackPen = it2->BackPen = it3->BackPen = 0 ;
  176.         it1->DrawMode = it2->DrawMode = it3->DrawMode = JAM1 ;
  177.  
  178.         norm1 = new char[strlen(t)+1] ;
  179.         norm2 = new char[strlen(t)+1] ;
  180.         under = new char[2] ;
  181.  
  182.         underkey(t) ;
  183.  
  184.         CopyMem(glist->ng->ng_TextAttr, underline, sizeof(struct TTextAttr)) ;
  185.         underline->tta_Style |= FSF_UNDERLINED ;
  186.         font = OpenFont((TextAttr *)underline) ;
  187.  
  188.         for (i=l1=l2=0; t[i]; i++) {
  189.             if (t[i] == '_') {
  190.                 if (t[i+1]) under[0] = t[++i] ;
  191.                 underset = TRUE ;
  192.             }
  193.             else {
  194.                 if (underset) {
  195.                     norm2[l2++] = t[i] ;
  196.                 }
  197.                 else {
  198.                     norm1[l1++] = t[i] ;
  199.                 }
  200.             }
  201.         }
  202.         norm1[l1] = '\0' ;
  203.         norm2[l2] = '\0' ;
  204.         under[1] = '\0' ;
  205.  
  206.         if (l1) {
  207.             it1->IText = (UBYTE *)norm1 ;
  208.             it1->ITextFont = glist->ng->ng_TextAttr ;
  209.             if (underset) {
  210.                 it1->NextText = it2 ;
  211.                 it2->LeftEdge = short(IntuiTextLength(it1)) ;
  212.                 it2->IText = (UBYTE *)under ;
  213.                 it2->ITextFont = (TextAttr *)underline ;
  214.                 if (l2) {
  215.                     it2->NextText = it3 ;
  216.                     it3->LeftEdge = short(it2->LeftEdge + IntuiTextLength(it2)) ;
  217.                     it3->IText = (UBYTE *)norm2 ;
  218.                     it3->ITextFont = glist->ng->ng_TextAttr ;
  219.                 }
  220.             }
  221.         }
  222.         else if (underset) {
  223.             it1->IText = (UBYTE *)under ;
  224.             it1->ITextFont = (TextAttr *)underline ;
  225.             it1->NextText = it2 ;
  226.             it2->LeftEdge = short(IntuiTextLength(it1)) ;
  227.             it2->IText = (UBYTE *)norm2 ;
  228.             it2->ITextFont = glist->ng->ng_TextAttr ;
  229.         }
  230.     }
  231. }
  232.  
  233.  
  234. void fbutton::freelab()
  235. {
  236.     if (norm1) delete norm1 ;
  237.     if (norm2) delete norm2 ;
  238.     if (under) delete under ;
  239.  
  240.     if (it1) delete it1 ;
  241.     if (it2) delete it2 ;
  242.     if (it3) delete it3 ;
  243.  
  244.     if (underline) delete underline ;
  245.  
  246.     if (font) CloseFont(font) ;
  247. }
  248.  
  249.  
  250. void fbutton::set(const char *text)
  251. {
  252.     if (text) {
  253.     freelab() ;
  254.     initlab(text) ;
  255.     SetGadgetAttrs((Gadget *)gad, w, NULL,
  256.         GA_IntuiText,    it1,
  257.         TAG_END) ;
  258.     }
  259. }
  260.  
  261.  
  262. static int BoxImageCnt = 0 ;
  263. int InitBoxImage(void)
  264. {
  265.     if (BoxImageCnt) {
  266.         BoxImageCnt++ ;
  267.     }
  268.     else if (
  269.         BoxImage = (struct Image *)NewObject(NULL, (UBYTE *)FRAMEICLASS,
  270.         IA_FrameType,   FRAME_BUTTON,
  271.         IA_EdgesOnly,   TRUE,
  272.         TAG_END)) {
  273.         BoxImageCnt = 1 ;
  274.     }
  275.     else
  276.         BoxImageCnt = 0 ;
  277.  
  278.     return (BoxImageCnt) ;
  279. }
  280.  
  281. void FreeBoxImage(void)
  282. {
  283.     BoxImageCnt-- ;
  284.     if (!BoxImageCnt) {
  285.         // This is a DEFENSIVE programming test
  286.         // i.e. not needed under normal conditions
  287.         if (BoxImage) DisposeObject(BoxImage) ;
  288.     }
  289. }
  290.  
  291.  
  292. // ========================================================================
  293. // =============================== FBUT ===================================
  294. // ========================================================================
  295.  
  296. #define DRAW_NONE       0
  297. #define DRAW_IMAGE      1
  298. #define DRAW_INTUITEXT  2
  299. #define DRAW_TEXT       3
  300.  
  301. struct FButtonINST {
  302.     Image       *LabelImage ;
  303.     Image       *Img ;
  304.     IntuiText   *IText ;
  305.     STRPTR      Text ;
  306.     LONG        Mode ;
  307.     UWORD       *XPens ;
  308. } ;
  309.  
  310. static ULONG STDARGS dispatchFButton(Class *cl, Object *o, Msg msg);
  311.  
  312. static void    NotifyFButton(Class *, Object *, ULONG, long, gpInput *) ;
  313.  
  314. static ULONG   RenderFButton(Class *, Gadget *, gpRender *) ;
  315.  
  316. static void    FButtonLims(FButtonINST *inst, Gadget *g, GadgetInfo *gi) ;
  317.  
  318. static int FButtonCnt = 0 ;
  319.  
  320. static UWORD ditherData[] = { 0x5555, 0xAAAA } ;
  321.  
  322. int InitFButton(void)
  323. {
  324.     if (FButtonCnt) {
  325.         FButtonCnt++ ;
  326.     }
  327.     else if (!(BOOPSIfbutton = MakeClass(NULL, (UBYTE *)GADGETCLASS, NULL,
  328.         sizeof(FButtonINST), 0))) {
  329.         FButtonCnt = 0 ;
  330.     }
  331.     else {
  332.         BOOPSIfbutton->cl_Dispatcher.h_Entry = (HOOKFUNC)HookEntry ;
  333.         BOOPSIfbutton->cl_Dispatcher.h_SubEntry = (HOOKFUNC)dispatchFButton;
  334.         BOOPSIfbutton->cl_Dispatcher.h_Data = NULL ;
  335.         FButtonCnt = 1 ;
  336.     }
  337.     return FButtonCnt ;
  338. }
  339.  
  340. void FreeFButton(void)
  341. {
  342.     FButtonCnt-- ;
  343.     if (!FButtonCnt)
  344.         if (BOOPSIfbutton) FreeClass(BOOPSIfbutton) ;
  345. }
  346.  
  347. ULONG SAVEDS STDARGS dispatchFButton( Class *cl, Object *o, Msg msg)
  348. {
  349. FButtonINST *inst ;
  350. ULONG       retval = FALSE ;
  351. Object      *object ;
  352.  
  353.     GETA4 ;
  354.     switch (msg->MethodID) {
  355.     case OM_NEW:
  356.         if (object = (Object *)DoSuperMethodA(cl, o, msg)) {
  357.             inst = (FButtonINST *)INST_DATA(cl, object) ;
  358.             if ( FindTagItem(GA_Image, ((opSet *)msg)->ops_AttrList)) {
  359.                 inst->Img = (Image *)GetTagData(GA_Image,
  360.                     NULL,
  361.                     ((opSet *)msg)->ops_AttrList) ;
  362.             }
  363.             inst->XPens = (UWORD *)GetTagData(EGA_XPens, NULL,
  364.                     ((opSet *)msg)->ops_AttrList) ;
  365.             if ( FindTagItem(GA_Text, ((opSet *)msg)->ops_AttrList)) {
  366.                 inst->Text = (STRPTR)GetTagData(GA_Text,
  367.                     NULL,
  368.                     ((opSet *)msg)->ops_AttrList) ;
  369.                 inst->Mode = DRAW_TEXT ;
  370.             }
  371.             else if ( FindTagItem(GA_LabelImage, ((opSet *)msg)->ops_AttrList)) {
  372.                 inst->LabelImage = (Image *)GetTagData(GA_LabelImage,
  373.                     NULL,
  374.                     ((opSet *)msg)->ops_AttrList) ;
  375.                 inst->Mode = DRAW_IMAGE ;
  376.             }
  377.             else if ( FindTagItem(GA_IntuiText, ((opSet *)msg)->ops_AttrList)) {
  378.                 inst->IText = (IntuiText *)GetTagData(GA_IntuiText,
  379.                     NULL,
  380.                     ((opSet *)msg)->ops_AttrList) ;
  381.                  inst->Mode = DRAW_INTUITEXT ;
  382.             }
  383.             else inst->Mode = DRAW_NONE ;
  384.             retval = (ULONG)object ;
  385.         }
  386.         break ;
  387.     case GM_HITTEST:
  388.         retval = DoSuperMethodA(cl, o, msg) ;
  389.         break ;
  390.     case GM_GOACTIVE:
  391.         {
  392.         gpInput *gpi = (gpInput *)msg ;
  393.             if (gpi->gpi_IEvent) {
  394.                 ((Gadget *)o)->Flags |= GFLG_SELECTED ;
  395.                 RenderFButton(cl, (Gadget *)o, (gpRender *)msg) ;
  396.                 retval = GMR_MEACTIVE ;
  397.             }
  398.             else
  399.                 retval = GMR_NOREUSE ;
  400.         }
  401.         break ;
  402.     case GM_GOINACTIVE:
  403.         ((Gadget *)o)->Flags &= ~GFLG_SELECTED ;
  404.         RenderFButton(cl, (Gadget *)o, (gpRender *)msg) ;
  405.         break ;
  406.     case GM_HANDLEINPUT:
  407.         {
  408.             gpInput *gpi = (gpInput *)msg ;
  409.             InputEvent *ie = gpi->gpi_IEvent ;
  410.             Gadget *g = (Gadget *)o ;
  411.             retval = GMR_MEACTIVE ;
  412.  
  413.             if (ie->ie_Class == IECLASS_RAWMOUSE) {
  414.                 switch (ie->ie_Code) {
  415.                     case SELECTUP:
  416.                         if ( (gpi->gpi_Mouse.X < 0) ||
  417.                            (gpi->gpi_Mouse.X > g->Width) ||
  418.                            (gpi->gpi_Mouse.Y < 0) ||
  419.                            (gpi->gpi_Mouse.Y > g->Height) ) {
  420.                                 retval = GMR_NOREUSE  ;
  421.                             }
  422.                         else {
  423.                             NotifyFButton(cl, o, 0, 0, (gpInput *)msg) ;
  424.                             retval = GMR_NOREUSE | GMR_VERIFY ;
  425.                         }
  426.                         break ;
  427.                     case MENUDOWN:
  428.                         retval = GMR_REUSE ;
  429.                         break ;
  430.                     default:
  431.                         retval = GMR_MEACTIVE ;
  432.                 }
  433.             }
  434.             else if (ie->ie_Class == IECLASS_TIMER) {
  435.                 if (( (gpi->gpi_Mouse.X < 0) ||
  436.                    (gpi->gpi_Mouse.X > g->Width) ||
  437.                    (gpi->gpi_Mouse.Y < 0) ||
  438.                    (gpi->gpi_Mouse.Y > g->Height) )) {
  439.                     if (g->Flags & GFLG_SELECTED) {
  440.                         g->Flags &= ~GFLG_SELECTED ;
  441.                         RenderFButton(cl, g, (gpRender *)msg) ;
  442.                     }
  443.                 }
  444.                 else {
  445.                     if (!(g->Flags & GFLG_SELECTED)) {
  446.                         g->Flags |= GFLG_SELECTED ;
  447.                         NotifyFButton(cl, o, OPUF_INTERIM, 0, (gpInput *)msg) ;
  448.                         RenderFButton(cl, g, (gpRender *)msg) ;
  449.                     }
  450.                 }
  451.             }
  452.         }
  453.         break ;
  454.     case OM_SET:
  455.         retval = DoSuperMethodA(cl, o, msg) ;
  456.         if ( FindTagItem(GA_Text, ((opSet *)msg)->ops_AttrList) ||
  457.              FindTagItem(GA_IntuiText, ((opSet *)msg)->ops_AttrList) ||
  458.              FindTagItem(GA_LabelImage, ((opSet *)msg)->ops_AttrList) ) {
  459.             RastPort *rp ;
  460.             Gadget *g  = (Gadget *)o ;
  461.  
  462.             inst = (FButtonINST *)INST_DATA(cl, o) ;
  463.  
  464.             if ( FindTagItem(GA_Text, ((opSet *)msg)->ops_AttrList)) {
  465.                 inst->Text = (STRPTR)GetTagData(GA_Text,
  466.                     (ULONG)inst->Text,
  467.                     ((opSet *)msg)->ops_AttrList) ;
  468.                 inst->Mode = DRAW_TEXT ;
  469.             }
  470.             else if ( FindTagItem(GA_LabelImage, ((opSet *)msg)->ops_AttrList)) {
  471.                 inst->LabelImage = (Image *)GetTagData(GA_LabelImage,
  472.                     (ULONG)inst->LabelImage,
  473.                     ((opSet *)msg)->ops_AttrList) ;
  474.                 inst->Mode = DRAW_IMAGE ;
  475.             }
  476.             else if ( FindTagItem(GA_IntuiText, ((opSet *)msg)->ops_AttrList)) {
  477.                 inst->IText = (IntuiText *)GetTagData(GA_IntuiText,
  478.                     (ULONG)inst->IText,
  479.                     ((opSet *)msg)->ops_AttrList) ;
  480.                  inst->Mode = DRAW_INTUITEXT ;
  481.             }
  482.             if (rp = ObtainGIRPort( ((opSet *)msg)->ops_GInfo) ) {
  483.  
  484.                 DoMethod(o, GM_RENDER, ((opSet *)msg)->ops_GInfo, rp, GREDRAW_REDRAW) ;
  485.                 ReleaseGIRPort(rp) ;
  486.             }
  487.         }
  488.         break ;
  489.     case GM_RENDER:
  490.         retval = RenderFButton(cl, (Gadget *)o, (gpRender *)msg) ;
  491.         break ;
  492.     default :
  493.         retval = DoSuperMethodA(cl, o, msg) ;
  494.         break ;
  495.     }
  496.     return retval ;
  497. }
  498.  
  499.  
  500. void SAVEDS NotifyFButton(Class *cl, Object *o, ULONG flags, long level, gpInput *gpi)
  501. {
  502. static TagItem tt[3] ;
  503.  
  504.     GETA4 ;
  505.     tt[0].ti_Tag = EGA_Pulse ;
  506.     tt[0].ti_Data = level  ;
  507.  
  508.     tt[1].ti_Tag = GA_ID ;
  509.     tt[1].ti_Data = ((Gadget *)o)->GadgetID ;
  510.  
  511.     tt[2].ti_Tag = TAG_DONE ;
  512.  
  513.     DoSuperMethod(cl, o, OM_NOTIFY, tt, gpi->gpi_GInfo, flags) ;
  514. }
  515.  
  516. ULONG SAVEDS RenderFButton(Class *cl, Gadget *g, gpRender *msg)
  517. {
  518. RastPort    *rp ;
  519. ULONG       retval = TRUE ;
  520. UWORD       *pens = msg->gpr_GInfo->gi_DrInfo->dri_Pens ;
  521. FButtonINST *inst = (FButtonINST *)INST_DATA(cl, (Object *)g) ;
  522. ULONG       state ;
  523. impDraw     imp ;
  524. IntuiText   *itext ;
  525. LONG        l, t ;
  526. IBox        cbox, fbox ;
  527. impFrameBox ifb ;
  528.  
  529.     GETA4 ;
  530.     if (msg->MethodID == GM_RENDER)
  531.         rp = msg->gpr_RPort ;
  532.     else
  533.         rp = ObtainGIRPort(msg->gpr_GInfo) ;
  534.     if (rp) {
  535.  
  536.         if (g->Flags & GFLG_SELECTED)
  537.             state = IDS_SELECTED ;
  538.         else if (g->Flags & GFLG_DISABLED)
  539.             state = IDS_DISABLED ;
  540.         else
  541.             state = IDS_NORMAL ;
  542.  
  543.         cbox.Left = g->LeftEdge ;
  544.         cbox.Top = g->TopEdge ;
  545.         cbox.Width = g->Width ;
  546.         cbox.Height = g->Height ;
  547.  
  548.         ifb.MethodID = IM_FRAMEBOX ;
  549.         ifb.imp_ContentsBox = &cbox ;
  550.         ifb.imp_FrameBox = &fbox ;
  551.         ifb.imp_DrInfo = msg->gpr_GInfo->gi_DrInfo ;
  552.         ifb.imp_FrameFlags = NULL ;
  553.         DoMethodA((Object *)inst->Img, (Msg)&ifb) ;
  554.  
  555.         SetAPen(rp, (g->Flags & GFLG_SELECTED)?pens[FILLPEN]:inst->XPens[BUTTONFILL_PEN]) ;
  556.         RectFill(rp, g->LeftEdge, g->TopEdge,
  557.             g->LeftEdge+g->Width-1, g->TopEdge+g->Height-1) ;
  558.  
  559.         imp.MethodID = IM_DRAWFRAME ;
  560.         imp.imp_RPort = rp ;
  561.         imp.imp_Offset.X = g->LeftEdge ;
  562.         imp.imp_Offset.Y = g->TopEdge ;
  563.         imp.imp_State = state ;
  564.         imp.imp_DrInfo = msg->gpr_GInfo->gi_DrInfo ;
  565.         imp.imp_Dimensions.Width = g->Width ;
  566.         imp.imp_Dimensions.Height = g->Height ;
  567.  
  568.         DoMethodA((Object *)inst->Img, (Msg)&imp) ;
  569.  
  570.         if (state == IDS_DISABLED) {
  571.             SetAPen(rp, 1) ;
  572.             SetAfPt(rp, ditherData, 1) ;
  573.             RectFill(rp, g->LeftEdge, g->TopEdge, g->LeftEdge+g->Width-1, g->TopEdge+g->Height-1) ;
  574.             SetAfPt(rp, NULL, 0) ;
  575.         }
  576.  
  577.         switch (inst->Mode) {
  578.         case DRAW_NONE:
  579.             break ;
  580.         case DRAW_TEXT:
  581.             Move(rp, g->LeftEdge, g->TopEdge+rp->TxBaseline) ;
  582.             Text(rp, inst->Text, strlen(inst->Text)) ;
  583.             break ;
  584.         case DRAW_INTUITEXT:
  585.             itext = inst->IText ;
  586.             while (itext->NextText) itext = itext->NextText ;
  587.             l = IntuiTextLength(itext) + itext->LeftEdge ;
  588.             l = g->LeftEdge + 1 + (g->Width - l - 2) / 2 ;
  589.             t = g->TopEdge + 1 + (g->Height - itext->ITextFont->ta_YSize -2) / 2 ;
  590.             PrintIText(rp, inst->IText, l, t) ;
  591.             break ;
  592.         case DRAW_IMAGE:
  593.             // ne pas afficher les images trop grandes pour le gadget
  594.  
  595.             if (inst->LabelImage->Width < g->Width &&
  596.                 inst->LabelImage->Height < g->Height) {
  597.  
  598.             // Centrage de l'image
  599.             l = g->LeftEdge + (g->Width - inst->LabelImage->Width) /  2 ;
  600.             t = g->TopEdge + (g->Height - inst->LabelImage->Height) /  2 ;
  601.             DrawImageState(rp,
  602.                 inst->LabelImage,
  603.                 l, t,
  604.                 state,
  605.                 msg->gpr_GInfo->gi_DrInfo) ;
  606.             }
  607.             break ;
  608.         }
  609.         if (msg->MethodID != GM_RENDER)
  610.             ReleaseGIRPort(rp) ;
  611.  
  612.     }
  613.     else
  614.         retval = FALSE ;
  615.     return retval ;
  616. }
  617.  
  618.  
  619. @
  620.  
  621.  
  622. 1.3
  623. log
  624. @*** empty log message ***
  625. @
  626. text
  627. @d1 1
  628. a1 1
  629. //$Id$
  630. d54 64
  631. a117 1
  632. BOOL    underset = FALSE ;
  633. a118 1
  634. int i, l1, l2 ;
  635. d120 4
  636. a123 2
  637.     InitBoxImage() ;
  638.     InitFButton() ;
  639. d133 1
  640. a133 1
  641.         it1->FrontPen = it2->FrontPen = it3->FrontPen = gl->gpen ;
  642. a141 1
  643.         if (def) gl->setdefault(TRUE) ;
  644. d143 1
  645. a143 1
  646.         CopyMem(gl->ng->ng_TextAttr, underline, sizeof(struct TTextAttr)) ;
  647. d167 1
  648. a167 1
  649.             it1->ITextFont = gl->ng->ng_TextAttr ;
  650. d177 1
  651. a177 1
  652.                     it3->ITextFont = gl->ng->ng_TextAttr ;
  653. d187 1
  654. a187 1
  655.             it2->ITextFont = gl->ng->ng_TextAttr ;
  656. d190 1
  657. a191 19
  658.     gad = gl->gad = (Gadget *)NewObject(BOOPSIfbutton, NULL,
  659.             GA_ID,          id,
  660.             GA_Top,         gl->ng->ng_TopEdge,
  661.             GA_Left,        gl->ng->ng_LeftEdge,
  662.             GA_Width,       gl->ng->ng_Width,
  663.             GA_Height,      gl->ng->ng_Height,
  664.  
  665.             GA_Immediate,   TRUE,
  666.             GA_RelVerify,   TRUE,
  667.  
  668.             GA_Previous,    gl->gad,
  669.             GA_IntuiText,   it1 ,
  670.             GA_Image,       BoxImage,
  671.  
  672.             GA_UserData,    EGA_Pulse,
  673.             GA_Disabled,    disable,
  674.             EGA_XPens,      gl->win->ws->xpens,
  675.  
  676.             TAG_END) ;
  677. d193 1
  678. a193 4
  679.     if (def) gl->setdefault(FALSE) ;
  680. }
  681.  
  682. fbutton::~fbutton()
  683. a204 1
  684.     if (gad) DisposeObject(gad) ;
  685. a205 2
  686.     FreeFButton() ;
  687.     FreeBoxImage() ;
  688. d208 2
  689. a209 1
  690. void fbutton::select(BOOL sel, BOOL disable)
  691. d211 3
  692. d215 1
  693. a215 2
  694.         GA_Selected,    sel,
  695.         GA_Disabled,    disable,
  696. a216 17
  697.     RefreshGList((Gadget *)gad, w, NULL, 1);
  698. }
  699.  
  700.  
  701. void fbutton::keystroke(BOOL shifted)
  702. {
  703.     select(TRUE) ;
  704.     Delay(5) ;
  705.     select(FALSE) ;
  706.     Delay(5) ;
  707.     gadget::action(NULL, NULL) ;
  708. }
  709.  
  710. void fbutton::action(unsigned long classe, unsigned short code)
  711. {
  712.     if (classe != IDCMP_GADGETDOWN) {
  713.         gadget::action(classe, code) ;
  714. d410 35
  715. @
  716.  
  717.  
  718. 1.2
  719. log
  720. @affichage des images centrées (support imgbut)
  721. @
  722. text
  723. @d1 1
  724. d13 1
  725. d15 2
  726. d21 7
  727. a27 25
  728. #include <cxxproto/graphics.h>
  729. #include <cxxproto/intuition.h>
  730.  
  731. extern "C" {
  732.  
  733. extern struct ExecBase *SysBase ;
  734. void CopyMem( APTR source, APTR dest, unsigned long size );
  735. #pragma libcall SysBase CopyMem 270 09803
  736.  
  737. extern struct DosLibrary *DOSBase ;
  738. void Delay( long timeout );
  739. #pragma libcall DOSBase Delay c6 101
  740.  
  741. extern struct Library *UtilityBase ;
  742. struct TagItem *FindTagItem( Tag tagVal, struct TagItem *tagList );
  743. ULONG GetTagData( Tag tagValue, unsigned long defaultVal,
  744.         struct TagItem *tagList );
  745. #include <pragmas/utility_pragmas.h>
  746.  
  747. ULONG DoMethodA( Object *obj, Msg msg);
  748. ULONG DoSuperMethodA( struct IClass *cl, Object *obj, Msg message );
  749. ULONG DoSuperMethod( struct IClass *cl, Object *obj, unsigned long MethodID,
  750.         ... );
  751. void kprintf(STRPTR format, ...) ;
  752. }
  753. d29 2
  754. d40 2
  755. d49 1
  756. a49 1
  757.                STRPTR t, BOOL def) :    gadget(gl, func),
  758. d58 1
  759. d103 1
  760. a103 1
  761.             it1->IText = norm1 ;
  762. d108 1
  763. a108 1
  764.                 it2->IText = under ;
  765. d113 1
  766. a113 1
  767.                     it3->IText = norm2 ;
  768. d119 1
  769. a119 1
  770.             it1->IText = under ;
  771. d123 1
  772. a123 1
  773.             it2->IText = norm2 ;
  774. d143 2
  775. d166 1
  776. d169 1
  777. a169 1
  778. void fbutton::select(BOOL sel)
  779. d173 1
  780. d196 2
  781. a197 1
  782. int _STI_4000_FButton(void)
  783. d199 5
  784. a203 1
  785.     BoxImage = (struct Image *)NewObject(NULL, FRAMEICLASS,
  786. d205 6
  787. a210 1
  788.         TAG_END);
  789. d212 1
  790. a212 1
  791.     return (!BoxImage) ? 1 : 0 ;
  792. d215 1
  793. a215 1
  794. void _STD_4000_FreeFButton(void)
  795. d217 6
  796. a222 1
  797.     if (BoxImage) DisposeObject(BoxImage) ;
  798. d237 1
  799. a237 1
  800.     Image       *Image ;
  801. d241 1
  802. d244 1
  803. a244 2
  804. static ULONG __asm dispatchFButton(register __a0 Class *cl,
  805.     register __a2 Object *o, register __a1 Msg msg);
  806. d253 3
  807. d261 1
  808. a261 1
  809.     else if (!(BOOPSIfbutton = MakeClass(NULL, GADGETCLASS, NULL,
  810. d266 3
  811. a268 1
  812.         BOOPSIfbutton->cl_Dispatcher.h_Entry = (HOOKFUNC)dispatchFButton;
  813. d278 1
  814. a278 1
  815.         FreeClass(BOOPSIfbutton) ;
  816. d281 1
  817. a281 3
  818. ULONG __saveds __asm dispatchFButton(   register __a0 Class *cl,
  819.                                         register __a2 Object *o,
  820.                                         register __a1 Msg msg)
  821. d287 1
  822. d293 1
  823. a293 1
  824.                 inst->Image = (Image *)GetTagData(GA_Image,
  825. d297 2
  826. d399 1
  827. a399 1
  828. void __saveds NotifyFButton(Class *cl, Object *o, ULONG flags, long level, gpInput *gpi)
  829. d403 1
  830. d415 1
  831. a415 1
  832. ULONG __saveds RenderFButton(Class *cl, Gadget *g, gpRender *msg)
  833. d425 2
  834. d428 1
  835. d442 16
  836. d460 2
  837. a461 2
  838.         imp.imp_Offset.X = short(g->LeftEdge + 1) ;
  839.         imp.imp_Offset.Y = short(g->TopEdge + 1) ;
  840. d464 2
  841. a465 2
  842.         imp.imp_Dimensions.Width = short(g->Width - 1) ;
  843.         imp.imp_Dimensions.Height = short(g->Height - 1) ;
  844. d467 1
  845. a467 1
  846.         DoMethodA((Object *)inst->Image, (Msg)&imp) ;
  847. d469 6
  848. a474 8
  849.         SetAPen(rp, pens[TEXTPEN]) ;
  850.         SetDrMd(rp, JAM2) ;
  851.  
  852.         Move(rp, g->LeftEdge, g->TopEdge) ;
  853.         Draw(rp, g->LeftEdge, g->TopEdge+g->Height) ;
  854.         Draw(rp, g->LeftEdge+g->Width, g->TopEdge+g->Height) ;
  855.         Draw(rp, g->LeftEdge+g->Width, g->TopEdge) ;
  856.         Draw(rp, g->LeftEdge, g->TopEdge) ;
  857. @
  858.  
  859.  
  860. 1.1
  861. log
  862. @Initial revision
  863. @
  864. text
  865. @d45 6
  866. a50 3
  867. static Class *BOOPSIfbutton ;
  868. static int InitFButton(void) ;
  869. static void FreeFButton(void) ;
  870. d78 1
  871. a78 1
  872.         it1->FrontPen = it2->FrontPen = it3->FrontPen = 1 ;
  873. d458 8
  874. d468 1
  875. a468 1
  876.                 g->LeftEdge, g->TopEdge,
  877. d471 1
  878. @
  879.